package com.qf.gh.web.servlet;

import com.qf.gh.domain.Goods;
import com.qf.gh.domain.PageBean;
import com.qf.gh.service.GoodsService;
import com.qf.gh.service.impl.GoodaServiceImpl;
import com.qf.gh.utils.StrUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/goodsservlet")
public class GoodServlet extends BaseServlet{
    GoodsService goodsService=new GoodaServiceImpl();
    public String getGoodsListByTypeId(HttpServletRequest request, HttpServletResponse response){
        int typeId = Integer.parseInt(request.getParameter("typeId"));
        System.out.println(typeId);
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");
        int pageNum1 = 1;
        int pageSize1 = 2;
        if(StrUtils.isNotEmpty(pageNum)) {
            pageNum1 = Integer.parseInt(pageNum);
        }
        if(StrUtils.isNotEmpty(pageSize)) {
            pageSize1 = Integer.parseInt(pageSize);
        }
        PageBean pageBean = goodsService.findByPage(typeId, pageNum1, pageSize1);

        request.setAttribute("pageBean", pageBean);
        request.setAttribute("typeId", typeId);

        return "forward:/goodsList.jsp";
    }
    public String getGoodsById(HttpServletRequest request, HttpServletResponse response) {
        int id = Integer.parseInt(request.getParameter("id"));
        Goods goods=goodsService.findById(id);
        request.setAttribute("goods",goods);
        return "forward:/goodsDetail.jsp";
    }

}
